/*******************************************************************************
 *      CSE 531 – Distributed and Multiprocessor Operating Systems
 *
 *           Something of a scheduler for our fake threads.
 *
 *   Author: Denis Ryndine
 *   Email:  dryndine@asu.edu
 *   Date:   2010-11-06
 *
 *   531-scheduler.h: 
 *
 *
 ******************************************************************************/

#ifndef CSE531_FAKE_THREADS_SCHEDULER_H_
#define CSE531_FAKE_THREADS_SCHEDULER_H_


/*Return 0 if init was OK.*/
int sch531_init(void);

/*Start ticking. Note1: must be called after your threads init
(run q setup, etc). Note2: it does not return, if it does things failed.*/
void sch531_run(void);

/*Block=suspend the scheduler.*/
int sch531_block(void);

/*Unblock=resume the scheduler. */
int sch531_unblock(void);

/*The current context will be locked / thread can't be preempted.*/
int sch531_lock_context(void);

/*Unlock context / thread may be preempted.*/
int sch531_unlock_context(void);

/*Witin the fake-thread, if it needs sleep(), this is the call to use now 
 (Wrap this in thread_sleep(secs) in your threads implementation).  */
int sch531_thread_sleep(unsigned secs);

/*If the current thread wants to yield/give up rest of its time slice, it must
do this using this call (Wrap this in thread_yield() in your threads).*/
int sch531_thread_yield(void);

/*A special case of yield: after current thread locks its context and then 
calls this it can be swapped with another (see impl. details).
[ Note: this method can be used to for our semaphores: after P() removed thread
 from run Q it should call this ]*/
int sch531_thread_blocked(void);

#endif /*CSE531_FAKE_THREADS_SCHEDULER_H_ */

